Pure (programming Language)
   HOME

TheInfoList



OR:

Pure, successor to the equational language Q, is a dynamically typed, functional
programming language A programming language is a system of notation for writing computer programs. Programming languages are described in terms of their Syntax (programming languages), syntax (form) and semantics (computer science), semantics (meaning), usually def ...
based on
term rewriting In mathematics, computer science, and logic, rewriting covers a wide range of methods of replacing subterms of a formula with other terms. Such methods may be achieved by rewriting systems (also known as rewrite systems, rewrite engines, or reduc ...
. It has facilities for user-defined
operator Operator may refer to: Mathematics * A symbol indicating a mathematical operation * Logical operator or logical connective in mathematical logic * Operator (mathematics), mapping that acts on elements of a space to produce elements of another sp ...
syntax In linguistics, syntax ( ) is the study of how words and morphemes combine to form larger units such as phrases and sentences. Central concerns of syntax include word order, grammatical relations, hierarchical sentence structure (constituenc ...
, macros,
arbitrary-precision arithmetic In computer science, arbitrary-precision arithmetic, also called bignum arithmetic, multiple-precision arithmetic, or sometimes infinite-precision arithmetic, indicates that calculations are performed on numbers whose digits of precision are po ...
(multiple-precision numbers), and compiling to native code through the
LLVM LLVM, also called LLVM Core, is a target-independent optimizer and code generator. It can be used to develop a Compiler#Front end, frontend for any programming language and a Compiler#Back end, backend for any instruction set architecture. LLVM i ...
. Pure is
free and open-source software Free and open-source software (FOSS) is software available under a license that grants users the right to use, modify, and distribute the software modified or not to everyone free of charge. FOSS is an inclusive umbrella term encompassing free ...
distributed (mostly) under the
GNU Lesser General Public License The GNU Lesser General Public License (LGPL) is a free-software license published by the Free Software Foundation (FSF). The license allows developers and companies to use and integrate a software component released under the LGPL into their own ...
version 3 or later.


Overview

Pure comes with an
interpreter Interpreting is translation from a spoken or signed language into another language, usually in real time to facilitate live communication. It is distinguished from the translation of a written text, which can be more deliberative and make use o ...
and
debugger A debugger is a computer program used to test and debug other programs (the "target" programs). Common features of debuggers include the ability to run or halt the target program using breakpoints, step through code line by line, and display ...
, provides
automatic memory management In computer science, garbage collection (GC) is a form of automatic memory management. The ''garbage collector'' attempts to reclaim memory that was allocated by the program, but is no longer referenced; such memory is called ''garbage''. Gar ...
, has powerful functional and symbolic programming abilities, and interfaces to
libraries A library is a collection of Book, books, and possibly other Document, materials and Media (communication), media, that is accessible for use by its members and members of allied institutions. Libraries provide physical (hard copies) or electron ...
in C (e.g., for numerics, low-level protocols, and other such tasks). At the same time, Pure is a ''small'' language designed from scratch; its interpreter is not large, and the library modules are written in Pure. The syntax of Pure resembles that of Miranda and
Haskell Haskell () is a general-purpose, statically typed, purely functional programming language with type inference and lazy evaluation. Designed for teaching, research, and industrial applications, Haskell pioneered several programming language ...
, but it is a
free-format language In computer programming, a free-form language is a programming language in which the positioning of characters on the page in program text is insignificant. Program text does not need to be placed in specific columns as on old punched card syst ...
and thus uses explicit
delimiter A delimiter is a sequence of one or more Character (computing), characters for specifying the boundary between separate, independent regions in plain text, Expression (mathematics), mathematical expressions or other Data stream, data streams. An ...
s (rather than
off-side rule The off-side rule describes syntax of a computer programming language that defines the bounds of a code block via indentation. The term was coined by Peter Landin, possibly as a pun on the offside law in association football. An off-side ...
indents) to denote program structure. The Pure language is a successor of the equational programming language Q, previously created by the same author, Albert Gräf at the
University of Mainz The Johannes Gutenberg University Mainz () is a public research university in Mainz, Rhineland Palatinate, Germany. It has been named after the printer Johannes Gutenberg since 1946. it had approximately 32,000 students enrolled in around 100 a ...
, Germany. Relative to Q, it offers some important new features (such as local functions with
lexical scoping In computer programming, the scope of a name binding (an association of a name to an entity, such as a variable) is the part of a program where the name binding is valid; that is, where the name can be used to refer to the entity. In other parts ...
, efficient vector and matrix support, and the built-in C interface) and programs run much faster as they are compiled just-in-time to native code on the fly. Pure is mostly aimed at mathematical applications and
scientific computing Computational science, also known as scientific computing, technical computing or scientific computation (SC), is a division of science, and more specifically the Computer Sciences, which uses advanced computing capabilities to understand and s ...
currently, but its interactive interpreter environment, the C interface and the growing set of addon modules make it suitable for a variety of other uses, such as
artificial intelligence Artificial intelligence (AI) is the capability of computer, computational systems to perform tasks typically associated with human intelligence, such as learning, reasoning, problem-solving, perception, and decision-making. It is a field of re ...
, symbolic computation, and real-time multimedia processing Pure plug-ins are available for the
Gnumeric Gnumeric is a spreadsheet program that is part of the GNOME Free Software Desktop Project. Gnumeric version 1.0 was released on 31 December 2001. Gnumeric is distributed as free software under the GNU General Public License; it is intended to ...
spreadsheet and Miller Puckette's
Pure Data Pure Data (Pd) is a visual programming language developed by Miller Puckette in the 1990s for creating interactive computer music and multimedia works. While Puckette is the main author of the program, Pd is an open-source software, open-source ...
graphical multimedia software, which make it possible to extend these programs with functions written in the Pure language. Interfaces are also provided as library modules to
GNU Octave GNU Octave is a scientific programming language for scientific computing and numerical computation. Octave helps in solving linear and nonlinear problems numerically, and for performing other numerical experiments using a language that is mostly ...
,
OpenCV OpenCV (Open Source Computer Vision Library) is a Library (computing), library of programming functions mainly for Real-time computing, real-time computer vision. Originally developed by Intel, it was later supported by Willow Garage, then Itseez ...
,
OpenGL OpenGL (Open Graphics Library) is a Language-independent specification, cross-language, cross-platform application programming interface (API) for rendering 2D computer graphics, 2D and 3D computer graphics, 3D vector graphics. The API is typic ...
, the
GNU Scientific Library The GNU Scientific Library (or GSL) is a software library for numerical computations in applied mathematics and science. The GSL is written in C (programming language), C; wrappers are available for other programming languages. The GSL is part of ...
,
FAUST Faust ( , ) is the protagonist of a classic German folklore, German legend based on the historical Johann Georg Faust (). The erudite Faust is highly successful yet dissatisfied with his life, which leads him to make a deal with the Devil at a ...
,
SuperCollider SuperCollider is an environment and audio programming language released originally in 1996 by James McCartney for real-time audio synthesis and algorithmic composition.J. McCartneySuperCollider: A new real time synthesis language in Proc. Int ...
, and liblo (for
Open Sound Control Open Sound Control (OSC) is a protocol for networking sound synthesizers, computers, and other multimedia devices for purposes such as musical performance or show control. OSC's advantages include interoperability, accuracy, flexibility and en ...
(OSC)).


Examples

The
Fibonacci numbers In mathematics, the Fibonacci sequence is a sequence in which each element is the sum of the two elements that precede it. Numbers that are part of the Fibonacci sequence are known as Fibonacci numbers, commonly denoted . Many writers begin the s ...
(naive version): fib 0 = 0; fib 1 = 1; fib n = fib (n-2) + fib (n-1) if n>1; Better ( tail-recursive and
linear-time In theoretical computer science, the time complexity is the computational complexity that describes the amount of computer time it takes to run an algorithm. Time complexity is commonly estimated by counting the number of elementary operations p ...
) version: fib n = fibs (0,1) n with fibs (a,b) n = if n<=0 then a else fibs (b,a+b) (n-1); end; Compute the first 20 Fibonacci numbers: map fib (1..20); An
algorithm In mathematics and computer science, an algorithm () is a finite sequence of Rigour#Mathematics, mathematically rigorous instructions, typically used to solve a class of specific Computational problem, problems or to perform a computation. Algo ...
for the
n queens problem The eight queens puzzle is the problem of placing eight chess queens on an 8×8 chessboard so that no two queens threaten each other; thus, a solution requires that no two queens share the same row, column, or diagonal. There are 92 solutions. ...
which employs a
list comprehension A list comprehension is a syntactic construct available in some programming languages for creating a list based on existing lists. It follows the form of the mathematical '' set-builder notation'' (''set comprehension'') as distinct from the use o ...
to organize the backtracking search: queens n = search n 1 [] with search n i p = [reverse p] if i>n; = cat [search n (i+1) ((i,j):p) , j = 1..n; safe (i,j) p]; safe (i,j) p = ~any (check (i,j)) p; check (i1,j1) (i2,j2) = i1

i2 , , j1

j2 , , i1+j1

i2+j2 , , i1-j1

i2-j2; end;
While Pure uses
eager evaluation In a programming language, an evaluation strategy is a set of rules for evaluating expressions. The term is often used to refer to the more specific notion of a ''parameter-passing strategy'' that defines the kind of value that is passed to the ...
by default, it also supports lazy data structures such as streams (lazy
lists A list is a set of discrete items of information collected and set forth in some format for utility, entertainment, or other purposes. A list may be memorialized in any number of ways, including existing only in the mind of the list-maker, but ...
). For instance, David Turner's algorithmTurner, David A. SASL language manual. Tech. rept. CS/75/1. Department of Computational Science, University of St. Andrews 1975. for computing the stream of
prime numbers A prime number (or a prime) is a natural number greater than 1 that is not a product of two smaller natural numbers. A natural number greater than 1 that is not prime is called a composite number. For example, 5 is prime because the only ways ...
by trial division can be expressed in Pure: primes = sieve (2..inf) with sieve (p:qs) = p : sieve q = qs; q mod p&; end; Use of the & operator turns the tail of the sieve into a
thunk In computer programming Computer programming or coding is the composition of sequences of instructions, called computer program, programs, that computers can follow to perform tasks. It involves designing and implementing algorithms, step-by- ...
to delay its computation. The thunk is evaluated implicitly and then memoized (using call by need evaluation) when the corresponding part of the list is accessed, e.g.: primes!!(0..99); // yields the first 100 primes Pure has efficient support for vectors and matrices (similar to that of
MATLAB MATLAB (an abbreviation of "MATrix LABoratory") is a proprietary multi-paradigm programming language and numeric computing environment developed by MathWorks. MATLAB allows matrix manipulations, plotting of functions and data, implementat ...
and
GNU Octave GNU Octave is a scientific programming language for scientific computing and numerical computation. Octave helps in solving linear and nonlinear problems numerically, and for performing other numerical experiments using a language that is mostly ...
), including vector and matrix comprehensions. Namespaces, types and interfaces belong to the standard repertoire: nonfix nil; type bintree nil , bintree (bin x left right); outfix « »; namespace foo (« »); infixr (::^) ^; x^y = 2*x+y; namespace; interface stack with push s::stack x; pop s::stack; top s::stack; end; type stack []; push xs@[] x , push xs@(_:_) x = x:xs; pop (x:xs) = xs; top (x:xs) = x; As a language based on
term rewriting In mathematics, computer science, and logic, rewriting covers a wide range of methods of replacing subterms of a formula with other terms. Such methods may be achieved by rewriting systems (also known as rewrite systems, rewrite engines, or reduc ...
, Pure fully supports
symbolic computation In mathematics and computer science, computer algebra, also called symbolic computation or algebraic computation, is a scientific area that refers to the study and development of algorithms and software for manipulating mathematical expressions ...
with expressions. Here is an example showing the use of local rewriting rules to expand and
factor Factor (Latin, ) may refer to: Commerce * Factor (agent), a person who acts for, notably a mercantile and colonial agent * Factor (Scotland), a person or firm managing a Scottish estate * Factors of production, such a factor is a resource used ...
simple arithmetic expressions: expand = reduce with (a+b)*c = a*c+b*c; a*(b+c) = a*b+a*c; end; factor = reduce with a*c+b*c = (a+b)*c; a*b+a*c = a*(b+c); end; expand ((a+b)*2); // yields a*2+b*2 factor (a*2+b*2); // yields (a+b)*2 Calling C functions from Pure is very easy. E.g., for a
"Hello, World!" program A "Hello, World!" program is usually a simple computer program that emits (or displays) to the screen (often the Console application, console) a message similar to "Hello, World!". A small piece of code in most general-purpose programming languag ...
, the following imports the puts function from the
C library The C standard library, sometimes referred to as libc, is the standard library for the C programming language, as specified in the ISO C standard.ISO/ IEC (2018). '' ISO/IEC 9899:2018(E): Programming Languages - C §7'' Starting from the origina ...
and uses it to print the string "Hello, world!" on the terminal: extern int puts(char*); hello = puts "Hello, world!"; hello; Instead of manually compiling source files to LLVM bitcode modules, one can also place the source code into a Pure script, enclosing it in %< ... %> (inline code, e.g. C, Fortran 77/90 and so on).


See also

*
Functional programming In computer science, functional programming is a programming paradigm where programs are constructed by Function application, applying and Function composition (computer science), composing Function (computer science), functions. It is a declarat ...
*
Functional languages In computer science, functional programming is a programming paradigm where programs are constructed by applying and composing functions. It is a declarative programming paradigm in which function definitions are trees of expressions that map ...
*
Clean (programming language) Clean is a general-purpose purely functional programming language. Originally called the Concurrent Clean System or the Clean System, it has been developed by a group of researchers from the Radboud University in Nijmegen since 1987. Although ...


References

* Albert Gräf. "Signal Processing in the Pure Programming Language". ''Linux Audio Conference 2009''. * Michael Riepe
"Pure – eine einfache funktionale Sprache"
. ''Heise''.
"Interview With Albert Gräf"
blueparen. * Mark Boady
Introduction to Term Rewrite Systems and their Applications


Notes


External links

*
Pure at Github





Documentation Overview (html)



Pure quick reference

Using the Pure Interpreter

Using Pure with TeXmacs

The Pure TeXmacs Plugin
{{Programming languages Dynamically typed programming languages Functional languages Term-rewriting programming languages Programming languages created in 2008 High-level programming languages 2008 software Cross-platform free software Cross-platform software